import 'package:casdon/modules/recipe/data/model/recipe_today_model.dart';

class RecipeTodayListState {
  final RecipeTodayListTypeState dataNew; // 最新对应的数据
  final RecipeTodayListTypeState dataHot; // 最热对应的数据
  final TodayRecipeSortType? currentSort;

  RecipeTodayListState({
    RecipeTodayListTypeState? dataNew,
    RecipeTodayListTypeState? dataHot,
    TodayRecipeSortType? currentSort,
  })  : dataNew = dataNew ?? RecipeTodayListTypeState.initial(),
        dataHot = dataHot ?? RecipeTodayListTypeState.initial(
          sortType: TodayRecipeSortType.createTime,
        ),
        currentSort = currentSort;

  TodayRecipeSortType get activeSort =>
      currentSort ?? TodayRecipeSortType.view;

  RecipeTodayListState copyWith({
    RecipeTodayListTypeState? dataNew,
    RecipeTodayListTypeState? dataHot,
    TodayRecipeSortType? currentSort,
  }) {
    return RecipeTodayListState(
      dataNew: dataNew ?? this.dataNew,
      dataHot: dataHot ?? this.dataHot,
      currentSort: currentSort ?? this.currentSort,
    );
  }

  factory RecipeTodayListState.initial() => RecipeTodayListState();
}

class RecipeTodayListTypeState {
  final List<RecipeTodayModel> data;
  final int totalSize;
  final int page;
  final int pageSize;
  final bool isLoadingMore;
  final bool hasMore;
  final TodayRecipeSortType sortType;

  RecipeTodayListTypeState copyWith({
    List<RecipeTodayModel>? data,
    int? totalSize,
    int? page,
    int? pageSize,
    bool? isLoadingMore,
    bool? hasMore,
    TodayRecipeSortType? sortType,
  }) {
    return RecipeTodayListTypeState(
      data: data ?? this.data,
      totalSize: totalSize ?? this.totalSize,
      page: page ?? this.page,
      pageSize: pageSize ?? this.pageSize,
      isLoadingMore: isLoadingMore ?? this.isLoadingMore,
      hasMore: hasMore ?? this.hasMore,
      sortType: sortType ?? this.sortType,
    );
  }

  factory RecipeTodayListTypeState.initial({
    int pageSize = 20,
    TodayRecipeSortType sortType = TodayRecipeSortType.view,
  }) =>
      RecipeTodayListTypeState(
        data: const [],
        totalSize: 0,
        pageSize: pageSize,
        page: 1,
        isLoadingMore: false,
        hasMore: false,
        sortType: sortType,
      );

  RecipeTodayListTypeState({
    required this.data,
    this.totalSize = 0,
    this.page = 1,
    required this.pageSize,
    this.isLoadingMore = false,
    this.hasMore = false,
    this.sortType = TodayRecipeSortType.view,
  });
}
